﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using Abp.Domain.Values;
using DHJ.Cost.Tasks;

namespace DHJ.Cost.CostBooking
{
    public class BatchesString : ValueObject<BatchesString>
    {
        public const char Divider = ';';

        private BatchesString()
        {
        }

        public BatchesString(List<BatchIdentifier> batches)
        {
            if (!batches.Any())
            {
                throw new ArgumentException("Should at least have one batch!", nameof(batches));
            }

            var str = new StringBuilder();
            foreach (var batchIdentity in batches)
            {
                str.Append(batchIdentity);
                str.Append(Divider);
            }

            Value = str.ToString().TrimEnd(Divider);
        }

        public string Value { get; set; }

        [NotMapped]
        public List<BatchIdentifier> Identifiers => Value.Split(Divider).Select(BatchIdentifier.Parse).ToList();
    }
}